﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Keyki.NefClass.Kernel.Data;
using Keyki.NefClass.Kernel.Fuzzy.Rulles;

namespace Keyki.NefClass.Kernel.Fuzzy.ChooceRule
{
	/// <summary>
	/// Makes Rule base with rules with best performance in class
	/// </summary>
	public class BestForClassRule : AbstractRule
	{
		public override void Procedure(List<Antecedent> antecedents, DataSet dataSet, ref List<FuzzyRule> rules, int countRules)
		{
			int countClasses = dataSet.CountClasses;
			int lastElement = (int) Math.Ceiling((double) countRules/(double) countClasses);

			List<FuzzyRule> fuzzyRules = null;

			CreateAllRules(antecedents, dataSet, out fuzzyRules);
			for (int i = 0; i < countClasses; i++)
			{
				var rulesForClass = from rule in fuzzyRules where rule.Class == i orderby rule.Performance descending select rule;

				rules.AddRange(rulesForClass.GetRange(0, lastElement));
			} //for i
		}//Procedure
	}//BestForClassRule
}//Keyki.NefClass.Kernel.Fuzzy.ChooceRule
